package com.zkingsoft.action;


import com.matrix.core.constance.SystemMessageCode;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.web.BaseAction;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.anotations.RemoveRequestToken;
import com.zkingsoft.service.TesstService;

import org.springframework.stereotype.Controller;

import com.matrix.core.exception.GlobleException;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.matrix.core.anotations.SaveRequestToken;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.WebUtil;

import org.springframework.beans.factory.annotation.Autowired;

import com.zkingsoft.bean.Tesst;

/**
 * @description (用户管理)
 * @author jyy
 * @date 2017-12-29 14:18
 */
@Controller
@RequestMapping(value = "admin/tesst")
public class TesstAction extends BaseAction{

	@Autowired
	private TesstService tesstService;
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="Tesst_BEV";
	public static final String SAFEPATH="su";
	public static int time=0;
	/**
	 * 列表显示
	 */
	@RequestMapping(value =  SAFEPATH+"/showList")
	public @ResponseBody AjaxResult showList(Tesst tesst, PaginationVO pageVo) {
		return showList(tesstService, tesst, pageVo);
	}
   	
	/**
	 * 新增
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value =  SAFEPATH+"/addTesst")
	public @ResponseBody AjaxResult addTesst(Tesst tesst) {
	 	int i=tesstService.add(tesst);
	 	if(i > 0){
	 		return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "(用户管理)");
	 	}else {
			throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL);
		}
	}
	
	
	
	/**
	 * 修改
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value =  SAFEPATH+"/modifyTesst")
	public @ResponseBody AjaxResult modifyTesst(Tesst tesst) {
	   		tesst.setId(((Tesst)WebUtil.getSessionAttribute(BEV)).getId());
	   		AjaxResult result=modify(tesstService, WebUtil.getSessionAttribute(BEV), tesst, "(用户管理)");
			WebUtil.removeSessionAttribute(BEV);
			return  result;
	}
	
	
	
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value =  SAFEPATH+"/editForm")
	public String editForm(String id) {
		Tesst tesst;
		if (id != null) {
			tesst = tesstService.findById(id);
			WebUtil.getRequest().setAttribute("obj", tesst);
			WebUtil.setSessionAttribute(BEV, tesst);
		}
		return "admin/Tesst-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = SAFEPATH+"/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(tesstService, keys);
	}
  
}